package com.wang.hashmap;

public class User implements Comparable<User>{
    private String name;
    private Integer stuNo;

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", stuNo=" + stuNo +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getStuNo() {
        return stuNo;
    }

    public void setStuNo(Integer stuNo) {
        this.stuNo = stuNo;
    }

    public User(String name, Integer stuNo) {
        this.name = name;
        this.stuNo = stuNo;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        return stuNo != null ? stuNo.equals(user.stuNo) : user.stuNo == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (stuNo != null ? stuNo.hashCode() : 0);
        return result;
    }

    public User() {
    }

    @Override
    public int compareTo(User o) {
        int n1 = this.getName().compareTo(o.getName());
        int n2 = this.getStuNo()-o.getStuNo();
        return n1 == 0 ? n2 : n1;
    }
}
